import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/afterSales/api/v1';

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询整车保养记录'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询整车保养记录详情'
});
const getVehicleSoldsDesc = formatMessage({
    id: 'api.message.getVehicleSoldsDesc',
    defaultMessage: '车辆档案查询'
});
const newOrderDesc = formatMessage({
    id: 'api.message.newOrderDesc',
    defaultMessage: '新增整车保养记录'
});
const modifyDesc = formatMessage({
    id: 'api.message.modifyDesc',
    defaultMessage: '修改整车保养记录'
});
const exportDesc = formatMessage({
    id: 'api.message.exportDesc',
    defaultMessage: '导出整车保养记录'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/vehicleMaintainRecord/init`, null, dto.InitDataStruct)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getListDesc));
// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleMaintainRecords/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetailList = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/vehicleMaintainRecords/detail?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
};
//导入模板
export const importTemp = () => request(`${baseUrl}/vehicleMaintainRecords/importTemp`)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, null)).then(res => res.data);
// 快捷查询车辆档案
export const getVehicleSoldsQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds/simple?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getVehicleSoldsDesc));
};
// 查询车辆档案
export const getVehicleSolds = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getVehicleSoldsDesc));
};
//新增
export const newOrder = data => request(`${baseUrl}/vehicleMaintainRecords`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, newOrderDesc));
//修改
export const modifyOrder = (id, data) => request(`${baseUrl}/vehicleMaintainRecords/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, modifyDesc));
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/vehicleMaintainRecords/${id}/detail`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
// 导出
export const queryExport = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleMaintainRecords/export?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, exportDesc))
        .then(res => res.data);
};
// 导出
export const settlementExportExports = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleMaintainRecords/settlementExport?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};

